package cn.com.taiji.oospub.wechat.common.wxpay.pay;

import javax.servlet.http.HttpServletRequest;

public class CommonTools {

	
	public static String getIp(HttpServletRequest request) {
		String ip = request.getHeader("X-Real-IP");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("X-Forwarded-For");
        }
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
		if (ip != null && ip.trim().length() > 0) {
			if (ip.indexOf(",") > 0) {
				String ips[] = ip.split(",");
				return ips[ips.length - 1];
			} else {
				return ip;
			}
		} else {
			return "0.0.0.0";
		}
	}
}
